import os
import time
import pytest
import allure
import TestCase

from Base.InitDriver import init_driver
from Page.CommonPage import CommonPage
from Utils.XiaoMaUtils import XiaoMaUtils


from Utils.PerfDogUtils import PerfDogUtils


@allure.feature('TestCase_17: 首次进入蓝牙电话,首次启动流量消耗')
@allure.issue(
    '')

class TestCaseSpecial17:
    def setup_class(self):
        self.driver = init_driver()
        # 实例化页面
        # 桌面
        self.launcher_index_page = CommonPage(self.driver).get_launcher_index_page()
        self.launcher_app_list_page = CommonPage(self.driver).get_launcher_app_list_page()
        # 蓝牙电话
        self.bluetooth_phone_page = CommonPage(self.driver).get_bluetooth_phone_index_page()

        # 实例化PerfDogUtils的工具类
        # 开始监控
        self.perfDogUtils = PerfDogUtils()
        # 输入需监控的应用名, 如"xting", "music"
        self.perfDogUtils.start_test("bluetoothphone")

    def teardown_class(self):
        time.sleep(10)
        self.perfDogUtils.stop_test()
        # XiaoMaUtils.close_app('bluetoothphone')
        os.system("adb shell am force-stop com.hsae.bluetoothphone")

        XiaoMaUtils.close_app('launcher')
        # XiaoMaUtils.clear_data('bluetoothphone')
        os.system("adb shell pm clear com.hsae.bluetoothphone")
        self.driver.quit()

    @allure.story('step1:点击应用页,点击蓝牙电话图标')
    @pytest.mark.run(order=171)
    def test_special_17_1_click_list(self):
        try:
            self.launcher_index_page.click_app_list()
            self.launcher_app_list_page.click_appname(TestCase.BLUETOOTHPHONE)
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story('step2:进入蓝牙电话,查看页面加载完成')
    @pytest.mark.run(order=172)
    def test_special_17_2_click_list(self):
        try:
            text1 = self.bluetooth_phone_page.is_display_bluetoothphone_index()
            if text1 == True:
                print("进入应用成功")
            else:
                print("点击应用出现问题,无法进入")

        except Exception as e:
            raise e

        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)


if __name__ == 'main__':
    # pass
    pytest.main("-s testcase_special_bluetoothphone_17.py")
